<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对称二叉树 - 算法详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #2d2d2d;
            padding: 12px 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .code-dots {
            display: flex;
            gap: 8px;
        }
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .dot-red { background: #ff5f56; }
        .dot-yellow { background: #ffbd2e; }
        .dot-green { background: #27c93f; }
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
        }
        code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            color: #e6e6e6;
            line-height: 1.6;
        }
        .keyword { color: #c678dd; }
        .function { color: #61afef; }
        .string { color: #98c379; }
        .number { color: #d19a66; }
        .comment { color: #5c6370; }
        .operator { color: #56b6c2; }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .floating-icon {
            animation: float 3s ease-in-out infinite;
        }
        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto">
            <div class="text-center">
                <div class="mb-6">
                    <i class="fas fa-code-branch text-6xl floating-icon opacity-80"></i>
                </div>
                <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">对称二叉树</h1>
                <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                    探索二叉树的镜像之美，掌握递归与迭代的精妙算法
                </p>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-16">
        <!-- Problem Description -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-lg p-8 md:p-12 card-hover">
                <div class="flex items-center mb-6">
                    <i class="fas fa-book-open text-3xl text-purple-600 mr-4"></i>
                    <h2 class="text-3xl font-bold">题目描述</h2>
                </div>
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="drop-cap serif-font">给</span>定一个二叉树，检查它是否是镜像对称的。例如，二叉树 [1,2,2,3,4,4,3] 是对称的，而 [1,2,2,null,3,null,3] 不是。一棵对称二叉树满足：它的左右两个子树呈镜像关系。
                </p>
            </div>
        </section>

        <!-- Visual Representation -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-lg p-8 md:p-12">
                <div class="flex items-center mb-6">
                    <i class="fas fa-project-diagram text-3xl text-purple-600 mr-4"></i>
                    <h2 class="text-3xl font-bold">可视化示例</h2>
                </div>
                <div class="grid md:grid-cols-2 gap-8">
                    <div class="text-center">
                        <h3 class="text-xl font-semibold mb-4 text-green-600">
                            <i class="fas fa-check-circle mr-2"></i>对称二叉树
                        </h3>
                        <div class="mermaid">
                            graph TD
                            A[1] --> B[2]
                            A --> C[2]
                            B --> D[3]
                            B --> E[4]
                            C --> F[4]
                            C --> G[3]
                            style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                            style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                            style C fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                            style D fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                            style E fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                            style F fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                            style G fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                        </div>
                    </div>
                    <div class="text-center">
                        <h3 class="text-xl font-semibold mb-4 text-red-600">
                            <i class="fas fa-times-circle mr-2"></i>非对称二叉树
                        </h3>
                        <div class="mermaid">
                            graph TD
                            A[1] --> B[2]
                            A --> C[2]
                            B --> D[null]
                            B --> E[3]
                            C --> F[null]
                            C --> G[3]
                            style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                            style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                            style C fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                            style D fill:#e0e0e0,stroke:#999,stroke-width:2px,stroke-dasharray: 5 5
                            style E fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                            style F fill:#e0e0e0,stroke:#999,stroke-width:2px,stroke-dasharray: 5 5
                            style G fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Core Concepts -->
        <section class="mb-16">
            <div class="bg-gradient-to-r from-purple-50 to-pink-50 rounded-2xl p-8 md:p-12">
                <div class="flex items-center mb-6">
                    <i class="fas fa-lightbulb text-3xl text-purple-600 mr-4"></i>
                    <h2 class="text-3xl font-bold">核心考点</h2>
                </div>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-white rounded-xl p-6 card-hover">
                        <div class="flex items-center mb-3">
                            <i class="fas fa-sync-alt text-2xl text-purple-500 mr-3"></i>
                            <h3 class="text-xl font-semibold">递归思想</h3>
                        </div>
                        <p class="text-gray-700">通过递归比较左右子树的对应节点，优雅地解决镜像对称问题</p>
                    </div>
                    <div class="bg-white rounded-xl p-6 card-hover">
                        <div class="flex items-center mb-3">
                            <i class="fas fa-layer-group text-2xl text-pink-500 mr-3"></i>
                            <h3 class="text-xl font-semibold">迭代方法</h3>
                        </div>
                        <p class="text-gray-700">使用队列数据结构，层序遍历并成对比较节点</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Solution Approaches -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">
                <i class="fas fa-route mr-3 text-purple-600"></i>解题思路
            </h2>
            
            <!-- Recursive Approach -->
            <div class="bg-white rounded-2xl shadow-lg p-8 md:p-12 mb-8 card-hover">
                <h3 class="text-2xl font-bold mb-6 flex items-center">
                    <span class="bg-purple-600 text-white rounded-full w-10 h-10 flex items-center justify-center mr-3">1</span>
                    递归法
                </h3>
                <div class="mb-6">
                    <p class="text-lg text-gray-700 mb-4">
                        递归法的核心思想是将大问题分解为小问题。对于对称二叉树，我们需要检查：
                    </p>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-3"></i>
                            <span>左子树的左孩子与右子树的右孩子是否相等</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-3"></i>
                            <span>左子树的右孩子与右子树的左孩子是否相等</span>
                        </li>
                    </ul>
                </div>
                <div class="grid md:grid-cols-2 gap-6 mb-6">
                    <div class="bg-purple-50 rounded-lg p-4">
                        <h4 class="font-semibold mb-2 flex items-center">
                            <i class="fas fa-clock text-purple-600 mr-2"></i>时间复杂度
                        </h4>
                        <p class="text-2xl font-bold text-purple-600">O(n)</p>
                        <p class="text-sm text-gray-600">需要访问每个节点一次</p>
                    </div>
                    <div class="bg-pink-50 rounded-lg p-4">
                        <h4 class="font-semibold mb-2 flex items-center">
                            <i class="fas fa-memory text-pink-600 mr-2"></i>空间复杂度
                        </h4>
                        <p class="text-2xl font-bold text-pink-600">O(h)</p>
                        <p class="text-sm text-gray-600">递归调用栈的深度为树高</p>
                    </div>
                </div>
            </div>

            <!-- Iterative Approach -->
            <div class="bg-white rounded-2xl shadow-lg p-8 md:p-12 card-hover">
                <h3 class="text-2xl font-bold mb-6 flex items-center">
                    <span class="bg-purple-600 text-white rounded-full w-10 h-10 flex items-center justify-center mr-3">2</span>
                    迭代法
                </h3>
                <div class="mb-6">
                    <p class="text-lg text-gray-700 mb-4">
                        迭代法使用队列来存储需要比较的节点对，避免了递归调用栈的开销：
                    </p>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-3"></i>
                            <span>初始化队列，将根节点的左右子节点入队</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-3"></i>
                            <span>每次取出两个节点进行比较，并将它们的子节点按镜像顺序入队</span>
                        </li>
                    </ul>
                </div>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-purple-50 rounded-lg p-4">
                        <h4 class="font-